Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

native-hdr-histogram

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

native-hdr-histogram

node.js bindings for hdr histogram C implementation

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

native-hdr-histogram

node.js bindings for hdr histogram C implementation(version 0.9.10).

Build status Build Status

HDR Histogram is designed for recoding histograms of value measurements in latency and performance sensitive applications. Measurements show value recording times as low as 3-6 nanoseconds on modern (circa 2014) Intel CPUs. A Histogram's memory footprint is constant, with no allocation operations involved in recording data values or in iterating through them.

This library is blazingly fast, and you can use it to record histograms with no overhead. Linux, Mac OS X and Windows are all supported.

Install

npm i native-hdr-histogram --save

If you see any errors, you might need to configure your system to compile native addons: follow the instructions at node-gyp.

Example

'use strict'

const Histogram = require('native-hdr-histogram')
const max = 1000000
const key = 'record*' + max
const histogram = new Histogram(1, 100)

console.time(key)
for (let i = 0; i < max; i++) {
  histogram.record(Math.floor((Math.random() * 42 + 1)))
}
console.timeEnd(key)

console.log('80 percentile is', histogram.percentile(80))
console.log('99 percentile is', histogram.percentile(99))

console.log(histogram.percentiles())

API


Histogram(lowest, max, figures)

Create a new histogram with:

  • lowest: is the lowest possible number that can be recorded (default 1).
  • max: is the maximum number that can be recorded (default 100).
  • figures: the number of figures in a decimal number that will be maintained, must be between 1 and 5 (inclusive) (default 3).

histogram.record(value)

Record value in the histogram. Returns true if the recording was successful, false otherwise.


histogram.min()

Return the minimum value recorded in the histogram.


histogram.max()

Return the maximum value recorded in the histogram.


histogram.mean()

Return the mean of the histogram.


histogram.stddev()

Return the standard deviation of the histogram.


histogram.percentile(percentile)

Returns the value at the given percentile. percentile must be > 0 and <= 100, otherwise it will throw.


histogram.percentiles()

Returns all the percentiles.

Sample output:

[ { percentile: 0, value: 1 },
  { percentile: 50, value: 22 },
  { percentile: 75, value: 32 },
  { percentile: 87.5, value: 37 },
  { percentile: 93.75, value: 40 },
  { percentile: 96.875, value: 41 },
  { percentile: 98.4375, value: 42 },
  { percentile: 100, value: 42 } ]

histogram.encode()

Returns a Buffer containing a serialized version of the histogram


histogram.decode(buf)

Reads a Buffer and deserialize an histogram.


histogram.reset()

Resets the histogram so it can be reused.

Acknowledgements

This project was kindly sponsored by nearForm.

The pre-compilation work of this project is only possible because of mapbox's amazing work on node-pre-gyp. A lot of the functionality enabled is following the example set by their node-sqlite3 library.

License

This library is licensed as MIT

HdrHistogram_c is licensed as BSD license

zlib is licensed as zlib License

The scripts used in the scripts folder are modified BSD licensed scripts from the node-sqlite3 libary.

Keywords

FAQs

Package last updated on 04 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc